package edu.asu.sefcom.extract.profile;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jsoup.Jsoup;

public class StringUtil {

	public static String returnNormalPost(String start, String stop,
			String fileD, int refIndex) {
		int index = fileD.indexOf(start, refIndex);
		int st = fileD.indexOf(stop, index);
		String result = "";
		if (st > -1) {
			int header = start.length();
			result = fileD.substring(index + header, st);
		}
		return result;
	}

	
	public static int returnCount(String commentString) {
		commentString=""+removeHtml(commentString);
		commentString = commentString.replaceAll("[\\D]", "");
		// Pattern p1 = Pattern.compile("[0-9]*");
		// Matcher m1 = p1.matcher(commentString);
		// String res="0";
		// if(m1.find()){
		// res=m1.group();
		// }
		int i = 0;
		if (!org.jsoup.helper.StringUtil.isBlank(commentString)) {
			i = Integer.valueOf(commentString);
		}
		return i;
	}
	private static Object removeHtml(String article) {
		String ret = article.replaceAll("<br>", "");
		ret = ret.replaceAll("\\<.*?>", "");
		ret = ret.replaceAll("\\.*?>", "");
		// return ret;
		return Jsoup.parse(ret).text();
	}


	public static boolean isBlank(String targetStr) {
		// TODO Auto-generated method stub
		return org.jsoup.helper.StringUtil.isBlank(targetStr);
	}
}
